//
//  YBProjectDetailSummarizeViewController.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/9/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "YBProjectDetailSummarizeViewController.h"
#import "MyICRemarkView.h"
@interface YBProjectDetailSummarizeViewController ()
/** 备注 */
@property (nonatomic, strong) MyICRemarkView *remarkView;
/** 保存 */
@property (nonatomic, strong) UIButton *claim;
/**  判断是否保存  */
@property (assign, nonatomic) BOOL   isSave;

@end

@implementation YBProjectDetailSummarizeViewController

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if (self.remarkView.textView.text.length != 0) {
        [[NSUserDefaults standardUserDefaults] setObject:self.remarkView.textView.text forKey:self.model.ID];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.titlelabel.text = @"总结";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.remarkView];
    [self.view addSubview:self.claim];
}


- (void)action_claim{
    if (self.remarkView.textView.text.length > 0) {//
        [self netWorking_question];
    }else{
        [YJProgressHUD showMessage:@"请输入内容" inView:self.view];
    }
}
///保存
- (void)netWorking_question{
    __weak typeof(self) weakSelf = self;
    [YJProgressHUD showMessage:@"保存中..." duration:10 view:self.view];
    
    NSDictionary *dict = @{@"AI_ID":self.model.ID,
                           @"SUMMARY":self.remarkView.textView.text};
    [NetWorkingManager postWithUrlString:[NetWorkingURL getactmactionActCommonSummaryupdateSummary] Parameter:dict Success:^(id object) {
        [YJProgressHUD hide];
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
        
            if (self.block) {
                self.block();
            }
            [YJProgressHUD showMessage:@"保存成功" inView:weakSelf.view];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf.navigationController popViewControllerAnimated:YES];
            });
        }else{
            [YJProgressHUD showMessage:@"保存失败" inView:weakSelf.view];
        }
    } Fail:^(id object) {
        [YJProgressHUD hide];
        [YJProgressHUD showMessage:@"保存失败" inView:weakSelf.view];
    }];
}

#pragma mark - Setter


#pragma mark - Getters
- (MyICRemarkView *)remarkView{
    if (_remarkView == nil){
        _remarkView = [[MyICRemarkView alloc]initWithFrame:CGRectMake(0, LP_TopHeight + 20 * [UIScreen zj_screenHScale] , self.view.width, 220 * [UIScreen zj_screenHScale]) title:@""];
        _remarkView.backgroundColor = [UIColor clearColor];
        _remarkView.maxNumber = 1000;
        NSString *text = [[NSUserDefaults standardUserDefaults] objectForKey:self.model.ID];
        if (self.model.SUMMARY.length == 0) {
            _remarkView.textView.text = text;
        }else{
            _remarkView.textView.text = self.model.SUMMARY;
        }
    }
    return _remarkView;
}

- (UIButton *)claim{
    if (_claim == nil){
        _claim = [[UIButton alloc] initWithFrame:CGRectMake(35 * [UIScreen zj_screenWScale], self.view.height - 88 * [UIScreen zj_screenHScale], self.view.width - 70 * [UIScreen zj_screenWScale], 40 * [UIScreen zj_screenHScale])];
        _claim.backgroundColor = [UIColor themeColor];
        _claim.centerY = self.view.centerY;
        [_claim setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_claim setTitle:@"保存" forState:UIControlStateNormal];
        [_claim addTarget:self action:@selector(action_claim) forControlEvents:UIControlEventTouchUpInside];
        _claim.layer.cornerRadius = 4 * [UIScreen zj_screenWScale];
    }
    return _claim;
}
@end
